//
//  YHMachineRateMakeCell.m
//  YHApp
//
//  Created by -- on 2021/7/24.
//

#import "HAMachineRateMakeCell.h"
#import "HAMachineRateMakeMo.h"
#import "YHMachineRateMakeRateCell.h"

@interface HAMachineRateMakeCell ()<UITableViewDataSource,UITableViewDelegate>

/***/
@property (nonatomic, strong) UIView *topView;
/***/
@property (nonatomic, strong) UILabel *topTitLabel;
/***/
@property (nonatomic, strong) UIView *lineView;
/***/
@property (nonatomic, strong) UILabel *tit1Label;
/***/
@property (nonatomic, strong) UILabel *tit2Label;
/***/
@property (nonatomic, strong) UILabel *con1Label;
/***/
@property (nonatomic, strong) UILabel *con2Label;

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation HAMachineRateMakeCell

-(void)setModel:(HAMachineRateMakeMo *)model {
    _model = model;
    self.tit1Label.text = @"机具型号";
    self.tit2Label.text = @"机具编码";
    self.con1Label.text = _model.name;
    self.con2Label.text = _model.sn;
    
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _model.rates.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    YHMachineRateMakeRatesModel *rateMo = _model.rates[indexPath.row];
    CGFloat h = 54;
    h += (54+28) * rateMo.item.count;
    return h;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YHMachineRateMakeRateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHMachineRateMakeRateCellID"];
    if (!cell) {
        cell = [[YHMachineRateMakeRateCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YHMachineRateMakeRateCellID"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.rateModel = _model.rates[indexPath.row];
    return cell;
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.height.mas_offset(54);
    }];
    
    [self.topTitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(20);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(self.topView.mas_bottom).offset(53.5);
        make.height.mas_offset(0.8);
    }];
    
    [self.tit1Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topView.mas_bottom).offset(20);
        make.left.mas_equalTo(20);
        make.width.mas_offset(68);
        make.height.mas_offset(15);
    }];
    
    [self.con1Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(self.tit1Label);
        make.left.mas_equalTo(self.tit1Label.mas_right).offset(10);
    }];
    
    [self.tit2Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(20);
        make.left.mas_equalTo(20);
        make.width.mas_offset(68);
        make.height.mas_offset(15);
    }];
    
    [self.con2Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(self.tit2Label);
        make.left.mas_equalTo(self.tit2Label.mas_right).offset(10);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(54*3);
        make.bottom.mas_equalTo(0);
    }];
}

- (UIView *)topView
{
    if (!_topView) {
        _topView = [UIView ha_createView];
        _topView.backgroundColor = [UIColor khaBGColor];
        [self.contentView addSubview:_topView];
    }
    return _topView;
}

- (UILabel *)topTitLabel
{
    if (!_topTitLabel) {
        _topTitLabel = [UILabel ha_NLabelWithFont:15 textColor:@"#000000" text:@"机具信息" alignment:0];
        [self.topView addSubview:_topTitLabel];
    }
    return _topTitLabel;
}

- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [UIView ha_createView];
        _lineView.backgroundColor = [UIColor khaBGColor];
        [self.contentView addSubview:_lineView];
    }
    return _lineView;
}

- (UILabel *)tit1Label
{
    if (!_tit1Label) {
        _tit1Label = [UILabel ha_BLabelWithFont:15 textColor:@"#111a34" text:@"" alignment:0];
        [self.contentView addSubview:_tit1Label];
    }
    return _tit1Label;
}

- (UILabel *)con1Label
{
    if (!_con1Label) {
        _con1Label = [UILabel ha_BLabelWithFont:15 textColor:@"#45485D" text:@"" alignment:2];
        [self.contentView addSubview:_con1Label];
    }
    return _con1Label;
}

- (UILabel *)tit2Label
{
    if (!_tit2Label) {
        _tit2Label = [UILabel ha_NLabelWithFont:15 textColor:@"#111a34" text:@"" alignment:0];
        [self.contentView addSubview:_tit2Label];
    }
    return _tit2Label;
}

- (UILabel *)con2Label
{
    if (!_con2Label) {
        _con2Label = [UILabel ha_NLabelWithFont:15 textColor:@"#45485D" text:@"" alignment:2];
        [self.contentView addSubview:_con2Label];
    }
    return _con2Label;
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero];
        // 去掉滚动条
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        // 设置背景颜色
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.contentView addSubview:_tableView];
    }
    return _tableView;
}


@end
